'''
Created on 07/07/2010

@author: Mar
'''
import unittest
from SimpleIndirectionBlock import *




class SimpleIndirectionBlockTest(unittest.TestCase):


    def setUp(self):
        self.block = SimpleIndirectionBlock()
        self.block.addDataPointer(1000, 1)
        self.block.addDataPointer(1001, 2)
        self.block.addDataPointer(1002, 3)
        self.block.addDataPointer(1003, 4)
        self.block.addDataPointer(1004, 5)
        


    def tearDown(self):
        pass


    def testHasSpace(self):
        self.assertTrue(self.block.hasSpace())


    def testAddDataPointer(self):
        self.block.addDataPointer(1010, 11)
        self.assertTrue(self.block.getDataBlockPointers().__contains__(1010))
        self.assertEqual(self.block.getDataBlockPointers().get(1000), 1)
        
        
        
    def testRemoveDataPointer(self):
        self.block.addDataPointer(2000, 5)
        self.block.removeDataPointer(2000)
        self.assertTrue(not(self.block.getDataBlockPointers().__contains__(2000)))
        
        
    def testContains(self):
        self.block.addDataPointer(1234, 56)
        self.assertTrue(self.block.getDataBlockPointers().__contains__(1234))
        
    def testGetBlocks(self):
        self.list = self.block.getBlocks()
        self.assertTrue(self.list.__len__() == 5)
        self.assertEqual(self.list.__len__(), 5)
        self.assertEqual(self.list[0], 1000)
        self.assertEqual(self.list[1], 1001)
        self.assertEqual(self.list[2], 1002)
        self.assertEqual(self.list[3], 1003)
        self.assertEqual(self.list[4], 1004)
        self.assertTrue(self.block.getDataBlockPointers().__contains__(1000))
        self.assertEqual(self.block.getDataBlockPointers().get(1000), 1)
        
        
    

if __name__ == "__main__":
    #import sys;sys.argv = ['', 'Test.testName']
    unittest.main()
    
suite = unittest.TestLoader().loadTestsFromTestCase(SimpleIndirectionBlockTest)
unittest.TextTestRunner(verbosity=2).run(suite)